package com.iflysse.controller;


import com.iflysse.common.ResultEnum;
import com.iflysse.pojo.bo.CommonBoResp;
import com.iflysse.pojo.bo.common.PageBeanBoReq;
import com.iflysse.pojo.bo.common.PageBeanBoResp;
import com.iflysse.pojo.bo.req.DealResourceFeedbackBoReq;
import com.iflysse.pojo.bo.req.ResourceFeedbackBoReq;
import com.iflysse.pojo.bo.resp.ResourceFeedbackBoResp;
import com.iflysse.pojo.vo.common.CommonVoResp;
import com.iflysse.pojo.vo.req.DealResourceFeedbackVoReq;
import com.iflysse.pojo.vo.req.PageBeanVoReq;
import com.iflysse.pojo.vo.req.ResourceFeedbackVoReq;
import com.iflysse.pojo.vo.resp.ResourceFeedbackResp;
import com.iflysse.pojo.vo.resp.ResourceFeedbackVoResp;
import com.iflysse.services.ResourceFeedbackService;
import com.iflysse.util.CommonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/resourceFeedback")
@Api(value = "老师端资源反馈接口")
@Log4j
public class ResourceFeedbackController {


    @Autowired
    private ResourceFeedbackService resourceFeedbackService;

    /**
     * 根据条件查询资源反馈列表
     */
    @PostMapping("/queryResourceFeedbackByCond")
    @ApiOperation(value = "根据条件查询资源反馈列表")
    public ResourceFeedbackVoResp doQueryResourceFeedbackByCond(ResourceFeedbackVoReq resourceFeedbackVoReq){

        ResourceFeedbackVoResp resourceFeedbackVoResp=new ResourceFeedbackVoResp();
        try {

            log.info("根据条件查询资源反馈列表参数bean:"+resourceFeedbackVoReq);

            ResourceFeedbackBoReq resourceFeedbackBoReq=  CommonUtil.objToObj(resourceFeedbackVoReq, ResourceFeedbackBoReq.class);

            PageBeanVoReq pageBeanVoReq=new PageBeanVoReq();
            pageBeanVoReq.setPageIndex(Integer.valueOf(resourceFeedbackVoReq.getPageIndex()));
            pageBeanVoReq.setPageSize(resourceFeedbackVoReq.getPageSize());

            PageBeanBoReq pageBeanBoReq= CommonUtil.objToObj(pageBeanVoReq, PageBeanBoReq.class);
            resourceFeedbackBoReq.setPageBeanBoReq(pageBeanBoReq);
            log.info("教师端查询反馈列表调用业务接口参数："+resourceFeedbackBoReq);
            PageBeanBoResp<ResourceFeedbackBoResp> pageBeanBoResp= resourceFeedbackService.getResourceFeedbackByCondition(resourceFeedbackBoReq);

            ResourceFeedbackResp result=CommonUtil.objToObj(pageBeanBoResp,ResourceFeedbackResp.class);
            resourceFeedbackVoResp.setResult(result);
            resourceFeedbackVoResp.setCode(ResultEnum.SUCCESS.getCode());
            resourceFeedbackVoResp.setMsg(ResultEnum.SUCCESS.getMsg());

            log.info("教师端查询反馈列表响应bean："+resourceFeedbackVoResp);
            return resourceFeedbackVoResp;
        }catch (Exception e){
            log.error("教室端查询学生反馈列表出现异常，信息为："+e);
            CommonUtil.printError(resourceFeedbackVoResp);

            return resourceFeedbackVoResp;
        }
    }
    /**
     * 处理资源反馈
     */
    @PostMapping("/dealResourceFeedback")
    @ApiOperation(value = "处理资源反馈")
    public CommonVoResp doDealResourceFeedback(DealResourceFeedbackVoReq dealResourceFeedbackVoReq){
        CommonVoResp commonVoResp=new CommonVoResp();
        try{
            log.info("处理资源反馈参数bean："+dealResourceFeedbackVoReq);
            DealResourceFeedbackBoReq dealResourceFeedbackBoReq=  CommonUtil.objToObj(dealResourceFeedbackVoReq, DealResourceFeedbackBoReq.class);
            log.info("教室端处理资源反馈调用业务接口参数："+dealResourceFeedbackBoReq);
            CommonBoResp commonBoResp=  resourceFeedbackService.dealResourceFeedback(dealResourceFeedbackBoReq);

            CommonUtil.printBoResultToVoResult(commonBoResp,commonVoResp);
            log.info("教室端处理资源反馈响应bean:"+commonVoResp);
            return commonVoResp;
        }catch (Exception e){
            log.error("教师端处理资源反馈出现异常，信息为："+e);
            CommonUtil.printError(commonVoResp);
            return commonVoResp;
        }
    }
}
